package cn.nextProject.Utils;

import org.springframework.context.annotation.Configuration;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

public class ProcessUtils {

    // 将表单数据转换为流程变量
    public static Map<String, Object> convertToVariables(Map<String, Object> formData) {
        Map<String, Object> variables = new HashMap<>();
        for (Map.Entry<String, Object> entry : formData.entrySet()) {
            // 特殊类型需要转换（如日期）
            if (entry.getValue() instanceof String) {
                String strVal = (String) entry.getValue();
                if (strVal.matches("\\d{4}-\\d{2}-\\d{2}")) {
                    try {
                        variables.put(entry.getKey(), new SimpleDateFormat("yyyy-MM-dd").parse(strVal));
                        continue;
                    } catch (ParseException ignored) {}
                }
            }
            variables.put(entry.getKey(), entry.getValue());
        }
        return variables;
    }

}
